<?PHP
include_once "./php/ini.php";
if ( isset ($_COOKIE["goldname"]))
{
    $_SESSION["login"] = $_COOKIE["goldname"];
}

function gererLogin()
{
    if ( isset ($_POST["deco"]))
    {
        echo '<script language="Javascript">
<!--
document.location.replace("http://dev.citu.fr/infinity/");
// -->
</script>';

        setcookie("goldname", $_SESSION["login"], time()-10);
        unset ($_SESSION["login"]);
    }

    if (( isset ($_POST["login"])) && ( isset ($_POST["connexion"])))
    {
        $login = $_POST['login'];
        $pass = $_POST['pass'];
        dbconnect();

        global $log_tmp;
        global $log_tmp2;
        global $mdp_tmp;
        global $mdp_tmp2;

        //from login
        $requete = "SELECT * FROM users WHERE nom_user='".$login."';";
        $req = mysql_query($requete);
        $r = mysql_fetch_assoc($req);
        $log_tmp = $r['nom_user'];
        $mdp_tmp = $r['pass_user'];

        //from pass
        $requete = "SELECT * FROM users WHERE pass_user='".$pass."';";
        $req = mysql_query($requete);
        $r2 = mysql_fetch_assoc($req);
        $log_tmp2 = $r2['nom_user'];
        $mdp_tmp2 = $r2['pass_user'];

        //compare
        if (($log_tmp != "") && ($mdp_tmp != "") && ($log_tmp == $log_tmp2) && ($mdp_tmp == $mdp_tmp2))
        {
            $sql = "SELECT * FROM users WHERE nom_user='".$login."';";
            $requete = mysql_query($sql);
            if (!$requete)
            {
                echo "SQL error : ", $sql;
                exit ;
            }
            else
            {
                while ($tab = mysql_fetch_assoc($requete))
                {
                    if ($tab['compte_active'] == 1)
                    {
                        $_SESSION["login"] = $_POST["login"];
                        $_SESSION["id_user"] = $tab['id_user'];

                    }

                }


                if ( isset ($_POST["remember"]))
                {
                    setcookie("goldname", $_SESSION["login"], time()+60*60*24*61);
                }
            }
        }
        dbclose();
    }


}

function affiche()
{
    echo '<form method="POST" action="">
                						<input type="submit" name="deco" value="Déconnexion">
                					</form><OBJECT id="virtool" style="position: relative; float: left;" CLASSID="CLSID:D4323BF2-006A-4440-A2F5-27E3E7AB25F8" ID="Virtools" WIDTH="640" HEIGHT="480" CODEBASE="http://a532.g.akamai.net/f/532/6712/5m/virtools.download.akamai.com/6712/player/install/installer.exe#Version=4,0,0,26">
                                            <PARAM NAME="SRC" VALUE="infinityMaquette.vmo">
                                            <EMBED SRC="infinityMaquette.vmo" TYPE="application/x-virtools" PLUGINSPAGE="http://player.virtools.com/" WIDTH="640" HEIGHT="480" NAME="Virtools">
                                            </EMBED>
                                        </OBJECT>
                                        
                                        <div id="upload_message" style="position: relative; float: left; overflow: auto; height: 480px; width: 300px;">
                                        </div>
                                       
                                        <div id="formulaire" style="float: left;">
                                            <input id="fileToUpload" type="file" size="45" name="fileToUpload" class="input">
                                            <br/>
                                            <button class="button" id="buttonUpload" onclick="return ajaxFileUpload();">
                                                Upload
                                            </button>
                                            <br/>
                                            <img id="loading" src="ajaxfileupload/loading.gif" style="display:none;" alt="loading">
                                        </div>
                                        <div id="preview_image">
                                        </div>';

}

function formulaire_login()
{
    echo "<form method='POST' action=''>
                                        <fieldset style = 'width: 250px; margin: auto;'> <legend> Identification </legend>
                                       <table><tr><td> Login</td><td> <input type='text' id='login' name='login' size='15'></td></tr>
                        			   <tr><td> pass </td><td><input type='password' id='pass' name='pass' size='15'></td></tr>
									   <tr><td colspan='2'><input type='checkbox' name='remember'>Se souvenir de moi</td></tr>
                                        <tr><td><input type='submit' value='Connexion' name='connexion' ></td><td><input type='submit' name='visiteur' value='Mode visiteur'></td></tr>
                                        </table>
										</fieldset></form>
                                        <a href='?status=new'>Créer un compte.</a><br />
                                        <a href='?status=pass'>Mot de pass oublié?</a>";
}

?>
